package com.qianchang.microfinance.view.mine.loan;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.qianchang.microfinance.R;
import com.qianchang.microfinance.global.ConstantAppInfo;
import com.qianchang.microfinance.view.base.BaseActivity;
import com.dm.library.adapter.BaseViewPagerAdapter;
import com.dm.library.adapter.FragmentPageInfo;
import com.umeng.analytics.MobclickAgent;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 我的借款
 */
public class MyLoanActivity extends BaseActivity {

    public static final String URL_TYPE = "url_type";
    @BindView(R.id.tab_loan_type)
    TabLayout tabLoanType;
    @BindView(R.id.viewpager)
    ViewPager viewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_loan);
        ButterKnife.bind(this);
        initData();

        // 友盟SDK在统计Fragment时，需要关闭Activity自带的页面统计，
        // 然后在每个页面中重新集成页面统计的代码(包括调用了 onResume 和 onPause 的Activity)。
        MobclickAgent.openActivityDurationTrack(false);
    }

    @Override
    protected void initData() {
        super.initData();
        setTitleName(getString(R.string.title_my_loan));
//        getData();
        initViewPager();
    }

    private void initViewPager() {
        BaseViewPagerAdapter adapter = new BaseViewPagerAdapter(this, getSupportFragmentManager(), getPagerInfo());
        viewPager.setAdapter(adapter);
        tabLoanType.setupWithViewPager(viewPager);
    }

    //    CASH("0", "现金贷"),COST("1", "消费贷"),DIYA("2", "抵押贷"),HOUSE_RENT("3", "租房分期"),CAMPUS("4", "学生贷"),OWNER("5", "业主贷");
    private FragmentPageInfo[] getPagerInfo() {
        if (!ConstantAppInfo.IS_ONLY_CASH) {
            //修改不同的status
            tabLoanType.setVisibility(View.VISIBLE);
            return new FragmentPageInfo[]{
                    new FragmentPageInfo(getString(R.string.Label_jinbao_loan), MyLoanJinbaoFragment.class, setBundleData(0, "cash")),
                    new FragmentPageInfo(getString(R.string.Label_student_loan), MyLoanStudentFragment.class, setBundleData(4, "campus")),
                    new FragmentPageInfo(getString(R.string.Label_owner_loan), MyLoanOwnerFragment.class, setBundleData(5, "owner")),
                    new FragmentPageInfo(getString(R.string.Label_mortgage_loan), MyLoanMortgageFragment.class, setBundleData(2, "diya"))
            };
        } else {
            tabLoanType.setVisibility(View.GONE);
            return new FragmentPageInfo[]{new FragmentPageInfo(getString(R.string.Label_jinbao_loan), MyLoanJinbaoFragment.class, setBundleData(0, "cash"))};
        }
    }

    public Bundle setBundleData(int productType, String urlType) {
        Bundle bundle = new Bundle();
        bundle.putInt(ConstantAppInfo.PROJECT_TYPE, productType);
        bundle.putString(URL_TYPE, urlType);
        return bundle;
    }


}
